<template xmlns:v-on="http://www.w3.org/1999/xhtml">
    <div id="excelList">
        <div class="excelListTop">
            <span @click='routerClick()'>通讯录</span> >
            <span> 导入通讯录</span>
        </div>
        <div class="excelListError" v-if="errorItems.length > 0">
            当前表格中有
            <span>{{errorItems.length}}条</span>错误，修改完成后请重新上传
            <span>（如有误，请调整Excel后重新上传）</span>
        </div>
        <div class="excelListList" v-if='errorItems.length > 0'>
            <ul class="excelListListTop">
                <li class='excelListLi leftBor'>行数</li>
                <li :title="item" class="excelListLi" v-for='item in titleItems'>
                    {{item}}
                </li>
            </ul>
            <ul class="listUl" v-for='(item,index) in errorItems'>
                <li class='excelListLi leftBor'>{{index+1}}</li>
                <li :title="iten" class="excelListLi" v-for='iten in item.itemValue'>
                    {{iten}}
                </li>
                <li class='excelListLi marLeft'>{{item.errorContext}}</li>
            </ul>
        </div>
        <div class="excelListError" v-if="updateItems.length > 0">
            待更新列表
        </div>
        <div class="excelListList" v-if='updateItems.length > 0'>
            <ul class="excelListListTop">
                <li class='excelListLi leftBor'>行数</li>
                <li class="excelListLi" v-for='item in titleItems'>
                    {{item}}
                </li>
            </ul>
            <ul class="listUl" v-for='(item,index) in updateItems'>
                <li class='excelListLi leftBor'>{{index+1}}</li>
                <li :title="iten" class="excelListLi" v-for='iten in item'>
                    {{iten}}
                </li>
            </ul>
        </div>
        <div class="excelListError" v-if="createItems.length > 0">
            待插入列表
        </div>
        <div class="excelListList" v-if='createItems.length > 0'>
            <ul class="excelListListTop">
                <li class='excelListLi leftBor'>行数</li>
                <li class="excelListLi" v-for='item in titleItems'>
                    {{item}}
                </li>
            </ul>
            <ul class="listUl" v-for='(item,index) in createItems'>
                <li class='excelListLi leftBor'>{{index+1}}</li>
                <li :title="iten" class="excelListLi" v-for='iten in item'>
                    {{iten}}
                </li>
            </ul>
        </div>
        <div class="button" @click="returnClick()" v-if='errorItems.length > 0'>
            重新上传
        </div>
        <div class="button" @click="okUp()" v-if='errorItems.length == 0'>
            确认导入
        </div>
    </div>
</template>
<script>
import { mapActions } from "vuex";
export default {
  name: "excelList",
  data() {
    return {
      updateItems: [],
      createItems: [],
      errorItems: [],
      titleItems: []
    };
  },
  created: function() {
    var arr = JSON.parse(sessionStorage.getItem("excelData"));
    if (arr.updateItems) {
      this.updateItems = arr.updateItems;
    }
    if (arr.createItems) {
      this.createItems = arr.createItems;
    }
    if (arr.errorItems) {
      this.errorItems = arr.errorItems;
      // console.log('errorItems:', this.errorItems)
    }
    if (arr.titleItems) {
      this.titleItems = arr.titleItems;
    }
    // sessionStorage.removeItem("excelData")
  },
  mounted() {},
  watch: {},
  methods: {
    //通讯录
    routerClick() {
      this.$router.push({
        path: "/home/address"
      });
    },
    //重新上传
    returnClick() {
      this.$router.push({
        path: "/excelUpload"
      });
    },
    //确认上传
    okUp() {
      var self = this;
      self
        .getbookconfirm({
          memberId: sessionStorage.getItem("memberId"),
          orgId: sessionStorage.getItem("ORGID")
        })
        .then(data => {
          if (data.statusCode == "200") {
            self.$message({
              message: "导入成功",
              type: "success"
            });
            self.$router.push({
              path: "/home/address"
            });
          } else {
            self.$message({
              message: data.statusMessage,
              type: "info"
            });
          }
        })
        .catch(msg => {
          self.$message("服务器异常");
        });
    },
    ...mapActions(["getbookconfirm"])
  }
};
</script>
<style scoped>
#excelList {
  width: 1008px;
  padding: 0 20px;
  margin: 30px auto;
  min-height: 100vh;
  overflow-y: auto;
}

.excelListTop span:nth-child(1) {
  color: #38adff;
  cursor: pointer;
}

.excelListError {
  width: 650px;
  height: 30px;
  background: rgba(255, 166, 0, 0.2);
  font-size: 14px;
  line-height: 30px;
  padding-left: 20px;
  margin: 20px 0;
  border-radius: 4px;
}

.excelListError span {
  color: #38adff;
}

.excelListList {
  width: 1008px;
  height: 700px;
  overflow: auto;
  position: relative;
  border: 1px solid #8d8d8d;
  padding: 2px;
}

.excelListListTop {
  height: 32px;
  white-space: nowrap;
  top: 0px;
}

.excelListListTop > li {
  background: #d4d4d4;
  border-top: 1px solid #a0a0a0;
}

.listUl {
  white-space: nowrap;
  height: 30px;
}

.listUl:hover > li {
  background: #d4d4d4;
}

.excelListLi {
  display: inline-block;
  width: 150px;
  height: 30px;
  line-height: 30px;
  border-right: 1px solid #a0a0a0;
  border-bottom: 1px solid #a0a0a0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leftBor {
  border-left: 1px solid #a0a0a0;
  margin-right: -4px;
}

.marLeft {
  margin-left: -4px;
}

.button {
  cursor: pointer;
  background: rgba(0, 174, 255, 0.815);
  color: white;
  width: 120px;
  height: 40px;
  font-size: 16px;
  letter-spacing: 1px;
  line-height: 40px;
  border-radius: 4px;
  text-align: center;
  margin: 30px auto;
}
</style>